package cc.shimeng.fucloud.tools;

import cc.shimeng.fucloud.entity.Subject;
import cc.shimeng.fucloud.repository.SubjectRepository;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Optional;

@Component
public class SubjectTool {

    @Autowired
    private SubjectRepository subjectRepository;

    @Tool(description = "获取所有科目信息", name = "subjectGetAll")
    public List<Subject> getAll() {
        return subjectRepository.findAll();
    }

    @Tool(description = "获取科目信息", name = "subjectGet")
    public Optional<Subject> get(@ToolParam(description = "科目ID") Integer id) {
        return subjectRepository.findById(id);
    }

    @Tool(description = "创建科目信息", name = "subjectSave")
    public Subject save(Subject subject) {
        return subjectRepository.save(subject);
    }

    @Tool(description = "删除科目信息", name = "subjectDelete")
    public void delete(@ToolParam(description = "科目ID") Integer id) {
        subjectRepository.deleteById(id);
    }
}